<template>
  <div class='container'>
    <el-dialog
      title="预览文章"
      :visible="previewDialogVisible"
      width="60%"
      @close='close'
      @open='open'>
      <div >
        <h2>{{articleData.title}}</h2>
        <span class="headerSpan">{{articleData.createTime | formatDate}}</span>
        <span class="headerSpan">{{articleId.username}}</span>
        <i class="el-icon-view"></i>
        <span class="headerSpan">{{articleData.visits}}</span>
      </div>
      <div v-html="articleData.articleBody" class="body">
        <!-- {{articleData.articleBody}} -->
      </div>

    </el-dialog>
  </div>
</template>

<script>
import { detail } from '@/api/hmmm/articles.js'
// import { timeFilter } from '@/filters/index.js'
export default {
  props: {
    previewDialogVisible: {
      type: Boolean,
      default: false
    },
    articleId: {
      required: true
    }
  },
  data () {
    return {
      articleData: {}
      // timeFilter: timeFilter
    }
  },
  methods: {
    // 关闭预览对话框
    close () {
      this.$emit('update:previewDialogVisible', false)
    },
    // 获取数据
    async open () {
      const res = await detail(this.articleId)
      // console.log(res)
      this.articleData = res.data
    }
  }
}
</script>

<style scoped lang='scss'>
  .body{
    background: rgb(245, 245, 245);
    padding: 10px;
  }
  .headerSpan{
    padding: 0 10px;
  }
</style>
